﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SCS.BLL;
using System.Data;
using SCS.Common;

public partial class Admin_RoleManage : System.Web.UI.Page
{
    private SCS_Roler _roler = new SCS_Roler();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindRoler();
        }
    }

    public void BindRoler()
    {
        DataSet _set = _roler.GetListByPage("", "Roler_ID", 0, 10);

        gvRole.DataSource = _set;
        gvRole.DataBind();
    }

    protected string CheckRoleIsEnable(object _isEnable)
    {
        string _enable = string.Empty;
        if (string.IsNullOrEmpty(_isEnable.ToString()) == false)
        {
            switch (_isEnable.ToString())
            {
                case "1":
                    _enable = "启用";
                    break;
                case "0":
                    _enable = "禁用";
                    break;
                default:
                    break;
            }
        }
        return _enable;
    }

    protected void btnRoleEnable_Click(object sender, EventArgs e)
    {
        GenerateOperatorRoler("1");
    }

    protected void btnRoleForbidden_Click(object sender, EventArgs e)
    {
        GenerateOperatorRoler("0");
    }

    public void GenerateOperatorRoler(string isEnable)
    {
        List<string> _RolerList = new List<string>();
        foreach (GridViewRow item in gvRole.Rows)
        {
            CheckBox cbxSelect = item.FindControl("cbxSelect") as CheckBox;
            if (cbxSelect != null && cbxSelect.Checked)
            {
                Label lblRoleID = item.FindControl("lblRoleID") as Label;
                _RolerList.Add(lblRoleID.Text.Trim());
            }
        }

        if (_RolerList.Count <= 0)
        {
            return;
        }

        SCS.Model.SCS_Operating_Log oOperatorLog = new SCS.Model.SCS_Operating_Log();
        if (isEnable == "1")
        {
            oOperatorLog.Log_Description = "启用角色";
        }
        else if (isEnable == "0")
        {
            oOperatorLog.Log_Description = "禁用角色";
        }

        oOperatorLog.Log_IP_Adress = ComputeInfo.getRemoteIP();
        oOperatorLog.Log_MAC_Address = "";
        oOperatorLog.Log_TimeStamp = DateTime.Now;
        oOperatorLog.Log_User_ID = "zhangli";//from session
        oOperatorLog.Object_Name = "";

        if (_roler.UpdateRolerList(_RolerList, oOperatorLog, isEnable) > 0)
        {
            BindRoler();
        }
    }
    protected void btnResearch_Click(object sender, EventArgs e)
    {
        BindRoler();
    }
}